import UsersModel from "@/models/UsersModel";
import {UserInterface} from "@/interface/UserInterface";

export default class UsersServices {
    /**
     * 更新用户
     * @param id 用户id
     * @param params
     */
    public static update(id: number | string, params?: object): Promise<any> {
        return UsersModel.update({...params}, {where: {id: id}})
    }

    /**
     * 获取用户列表
     */
    public static get(params?: UserInterface): Promise<UsersModel[] | UsersModel | null> {
        console.log("params", params)
        if (params && params.id) {
            return UsersModel.findOne({
                where: {
                    id: params.id || ""
                }
            })
        } else {
            return UsersModel.findAll()
        }

    }

    /**
     * 删除用户
     * @param id
     */
    public static delete(id: string | number | undefined): Promise<number> {
        return UsersModel.destroy({
            where: {
                id
            }
        })
    }

    /**
     * 新建用户
     * @param user
     */
    public static create(user: object): Promise<UsersModel> {
        console.log("{...user}", {...user})
        return UsersModel.create({...user})
    }

}